/**
检查CPU状态的命令
*/
var fs = require('fs');
var _ = require('underscore');
var cmdutils = require('../utils/cmdutils');
var os = require('os');
var exec = require('child_process').execSync;


exports.getStatus = function (){
  var ss = {}

  ss.uptime = os.uptime();
  ss.cpus = os.cpus();
  ss.loadavg = os.loadavg();
  ss.freemem = os.freemem();
  ss.totalmem = os.totalmem();



  return ss;

};


var _PROC_CPUINFO = '/proc/cpuinfo';

/**
  返回CPU型号等信息
*/
exports.getBanner = function (){
  var contents = fs.readFileSync(_PROC_CPUINFO, {encoding:'UTF-8',flag:'r'}).split('\n');
  var cpuBanner = [];

  var cpu = {};
  _.each(contents,function (element, index, list){
    // console.log(element);
    if(element.trim() == ''){
      if(index < contents.length - 1){
        cpuBanner.push(cpu);
        cpu = {};        
      }
    }else{
      var ss = element.trim().split(':');
      cpu[ss[0].trim()] = ss[1].trim()
    }

  });

  return cpuBanner;
};